package bishi2016;

import java.util.Scanner;

public class Huawei_QiShuiPing {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int initial;
		while(scanner.hasNext()){
			initial = scanner.nextInt();
			if(initial == 0){
				break;
			}
			getAllCount(initial);
		}
		scanner.close();
	}
	
	public static void getAllCount(int initial){
		if(initial == 0){
			System.out.println(0);
			return ;
		}
		int sum = 0;  
		while(initial > 1){
			if(initial == 2){
				sum += 1;  //找老板借一瓶汽水，然后再还给老板
				break;
			}
			sum += initial / 3; //使用3个空瓶子换1瓶汽水
			initial = initial % 3 + initial / 3; //等于换的汽水瓶再加上不足三个的
		}
		System.out.println(sum);
	}
}
